package com.experiment.aicommunityback.util;


import io.jsonwebtoken.*;

import java.util.Date;

public class JwtUtils {

    private static long time=1000*60*60;
    private static String signature="admin";
    public static String getToken(String name,String password){
        JwtBuilder jwtBuilder= Jwts.builder();
        return jwtBuilder
                .setHeaderParam("typ","JWT")
                .setHeaderParam("alg","HS256")
                .claim("name",name)
                .claim("password",password)
                .setSubject("admin")
                .setExpiration(new Date(System.currentTimeMillis()+time))
                .signWith(SignatureAlgorithm.HS256,signature)
                .compact();
    }

    public static boolean check_token(String token){
        if (token==null) {
            return false;
        }
        try {
            JwtParser parser = Jwts.parser();
            Jws<Claims> claimsJws = parser.setSigningKey(signature).parseClaimsJws(token);
        }catch (Exception e){
            return false;
        }
        return true;
    }
}
